package org.zxyj.web.shiro.credential;

import org.apache.shiro.authc.AuthenticationInfo;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authc.credential.SimpleCredentialsMatcher;
import org.zxyj.core.security.PasswordService;

/**
 * @author zhaoyong
 * @version 2016年3月2日
 */
public class DefensorCredentialMatcher extends SimpleCredentialsMatcher {

	private PasswordService passwordService;

	@Override
	public boolean doCredentialsMatch(AuthenticationToken token, AuthenticationInfo info) {
		UsernamePasswordToken usernamePasswordToken = (UsernamePasswordToken) token;
		Object accountCredentials = getCredentials(info);
		return passwordService.passwordsMatch(new String(usernamePasswordToken.getPassword()),
				(String) accountCredentials);
	}

	public void setPasswordService(PasswordService passwordService) {
		this.passwordService = passwordService;
	}

}